<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" href="../../css/ztree/demo.css" type="text/css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class="form-group">
				<div class="col-md-10">
					<ul id="treeDemo" class="ztree"></ul>
				</div>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
						<button class="btn btn-primary" type="submit" onclick="add()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>

	<script src="../../js/constant.js"></script>
	<script type="text/javascript" src="../../js/libs/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript" src="../../js/libs/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/my/ztree-menu.js"></script>
	<script type="text/javascript">
	layui.use('layer', function(){
	    var layer = layui.layer;
	});
	
		$.fn.zTree.init($("#treeDemo"), getSettting(), getMenuTree());
	
		var roleId = getUrlParam("roleId");
		initMenuDatas(roleId);
		
		function add() {
		    
		    var permissionIds = getCheckedMenuIds();

			$.ajax({
				type : 'post',
				url : domainName + '/api-b/menus/toRole?roleId=' + roleId,
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(permissionIds),
				success : function(data) {
					layer.msg("成功", {shift: -1, time: 1000}, function(){
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
                    });
				}
			});
		}
		
	</script>
</body>
</html>